package com.tsmti.lab.controller.system;

import com.tsmti.core.common.controller.BaseCrudController;
import com.tsmti.core.common.query.data.Queryable;
import com.tsmti.core.common.query.data.Sort;
import com.tsmti.core.util.ConvertUtil;
import com.tsmti.shiro.annotation.RequiresPathPermission;
import com.tsmti.system.entity.DataDictionary;
import com.tsmti.system.entity.DataDictionaryGroup;
import com.tsmti.system.service.DataDictionaryGroupService;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Package：com.tsmti.lab.controller.system
 * @Class：DataDirectoryController
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/5/16 16:13
 * @Company:
 * @Version：
 * @Modified By:
 */
@Controller
@RequestMapping("/system/dictionary")
@RequiresPathPermission("sys:dictionary")
public class DataDictionaryController extends BaseCrudController<DataDictionary,Long> {
    @Autowired
    private DataDictionaryGroupService dataDictionaryGroupService;
    @Override
    public void preList(Model model, HttpServletRequest request, HttpServletResponse response) {
        Long gid = ConvertUtil.getLongValue(request.getParameter("groupId"),0L);
        DataDictionaryGroup group = dataDictionaryGroupService.get(gid);
        model.addAttribute("group", group);
    }

    @Override
    public void preAjaxList(Queryable queryable, DetachedCriteria detachedCriteria, HttpServletRequest request,
                            HttpServletResponse response) {
        String gid = request.getParameter("groupId");
        queryable.addCondition("groupId", gid);
        super.preAjaxList(queryable, detachedCriteria, request, response);
    }

    @Override
    public void preEdit(DataDictionary entity, Model model, HttpServletRequest request, HttpServletResponse response) {
        String gid = request.getParameter("groupId");
        model.addAttribute("groupId", gid);
    }
}
